package com.example.test;

import java.util.ArrayList;
import java.util.List;

public class Solution {

    public static void main(String[] args) {
        Solution solution=new Solution();
        int[] nums={11,10,12};
        int[] values={1,2,3,4,5};
        int maxValue = solution.getMaxValue(nums, values);
        System.out.println(maxValue);
    }

    public int getMaxValue (int[] nums, int[] values) {
        // write code here
        int result=0;
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<nums.length;i++){
            list.add(nums[i]);
        }
        result=getListMaxValue(list,values,0);
        return result;
    }

    private int getListMaxValue(List<Integer> list, int[] values,int i){
        List<Integer> endList=new ArrayList<>(list);
        if(list.size()==1){
            return list.get(0)*values[i];
        }
        int max1=list.get(0)*values[i];
        i++;
        list.remove(0);
        max1+=getListMaxValue(list, values, i);
        i--;
        int max2=endList.get(endList.size()-1)*values[i];
        i++;
        endList.remove(endList.size()-1);
        max2+=getListMaxValue(endList, values, i);
        if(max1>=max2){
            return max1;
        }else{
            return max2;
        }
    }
}